﻿using System;
using System.IO;
using System.Xml;
using System.Collections;

namespace SyCODE.Blog
{
    /// <summary>
    /// Resource 的摘要说明
    /// </summary>
    public static class StringResource
    {
        /// <summary>
        /// 语言包
        /// </summary>
        private sealed class LanguagePack
        {
            private Hashtable lang = new Hashtable();

            public LanguagePack()
            {
                XmlDocument langDom = new XmlDocument();
                langDom.Load(Path.Combine(AppPath.GetAppRootPath(), @"string.config"));

                XmlNodeList fields = langDom.DocumentElement.ChildNodes;

                for (int i = 0; i < fields.Count; i++)
                {
                    this.lang.Add(fields[i].Attributes[0].Value, fields[i].InnerText);
                }
            }

            public string this[string name]
            {
                get
                {
                    if (this.lang.ContainsKey(name))
                        return (string)this.lang[name];
                    return String.Empty;
                }
            }
        }

        private static LanguagePack lp;

        public static string GetField(string name)
        {
            if (lp == null)
            {
                lp = new LanguagePack();
            }

            if (String.IsNullOrEmpty(name))
            {
                return name;
            }

            return lp[name];
        }
    }
}